import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text("Function Widget Demo"),
      ),
      body: AlertDialogWidget(),
    ),
  ));
}

class AlertDialogWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      child: const Text("对话框"),
      onPressed: () async {
        bool? delete = await showDeleteConfigDialog(context);
        if (delete == null) {
          print("取消删除");
        } else {
          print ("已确认删除");
        }
      },
    );
  }

  //  弹出对话框
  Future<bool?> showDeleteConfigDialog(context) {
    return showDialog<bool>(context: context, builder: (context) {
      return AlertDialog(
        title: const Text("提示"),
        content: const Text("您确定要删除当前文件吗?"),
        actions: <Widget>[
          TextButton(
            child: const Text("取消"),
            onPressed: () => Navigator.of(context).pop(),  //关闭对话框
          ),
          TextButton(
            child: const Text("删除"),
            onPressed: () => Navigator.of(context).pop(true), //关闭对话框
          ),
        ],
      );
    });
  }
}
